package org.a020;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLock2 {
	Lock lock = new ReentrantLock();
	 void m1(){
		 lock.lock();
		for(int i=0; i<10; i++) {
			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(i);
		}
		lock.unlock();
	}
	synchronized void m2(){
		lock.lock();
		System.out.println("m2...");
		lock.unlock();
	}
	public static void main(String[] args) {
		ReentrantLock2 lock = new ReentrantLock2();
		new Thread(lock::m1).start();
		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		new Thread(lock::m2).start();
	}
}
